<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <button class="btn1">启动循环定时器</button>
    <button class="btn2">移除定时器</button>
    <script>
      var stl = document.querySelector(".btn1");
      var stt;
      stl.onclick = function () {
        // setInterval() 间隔指定的毫秒数不停地执行指定的代码
        stt = setInterval(function () {
          console.log("hello");
        }, 100);
      };

      var btn = document.querySelector(".btn2");
      btn.onclick = function () {
        // clearInterval() 方法用于停止 setInterval() 方法执行的函数代码。
        clearInterval(stt);
      };
    </script>
  </body>
</html>
